package com.song.hbasechap_7_dll;

import java.io.IOException;

import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class VVLineImport extends Mapper<LongWritable ,Text , ImmutableBytesWritable , Put> {

	private  String family="data";
	private String  col= "mid";
	@Override
	protected void map(
			LongWritable key,
			Text value,
			Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		
		String linestr = value.toString();
		
		String[] seg = linestr.split(",");
		
		if(seg.length==3)
		{
			String uuid = seg[0];
			
			String mid = seg[1];
			String tsstr = seg[2];
			long ts = Long.parseLong(tsstr);
			byte[] rowkey = Bytes.toBytes(uuid);
			Put put = new Put( rowkey, ts);
			put.add(Bytes.toBytes(family), Bytes.toBytes(col),Bytes.toBytes(mid));
			context.write(new ImmutableBytesWritable(rowkey), put);
			context.getCounter("song-hbase", "data-import").increment(1);
		}
		
		
	}

	
	
	
	
	
}
